package io.renren.modules.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.JacksonUtils;
import io.renren.modules.edu.dao.TEduDepartmentDao;
import io.renren.modules.edu.dto.TEduDepartmentDTO;
import io.renren.modules.edu.entity.TEduDepartmentEntity;
import io.renren.modules.edu.service.TEduDepartmentService;
import io.renren.modules.edu.vo.ElSelectOptionsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 部门信息表
 *
 * @author zwp zwp
 * @since 1.0.0 2022-07-11
 */
@Slf4j
@Service
public class TEduDepartmentServiceImpl extends ServiceImpl<TEduDepartmentDao, TEduDepartmentEntity> implements TEduDepartmentService {

    @Override
    public void save(TEduDepartmentDTO tEduDepartmentDTO) {
        TEduDepartmentEntity tEduDepartmentEntity = JacksonUtils.obj2pojo(tEduDepartmentDTO, TEduDepartmentEntity.class);
        this.baseMapper.insert(tEduDepartmentEntity);
    }

    @Override
    public void update(TEduDepartmentDTO tEduDepartmentDTO) {
        TEduDepartmentEntity tEduDepartmentEntity = JacksonUtils.obj2pojo(tEduDepartmentDTO, TEduDepartmentEntity.class);
        this.updateById(tEduDepartmentEntity);
    }

    @Override
    public List<ElSelectOptionsVO> queryEdudepartment(Map<String, Object> params) {
        log.info("获取部门列表");
        // 查询所有的部门信息
        List<TEduDepartmentEntity> eduDepartmentEntityList = this.baseMapper.selectList(null);

        List<ElSelectOptionsVO> list = new ArrayList<>();
        eduDepartmentEntityList.forEach(e -> {
            ElSelectOptionsVO elSelectOptionsVO = new ElSelectOptionsVO();
            elSelectOptionsVO.setLabel(e.getDepartmentName());
            elSelectOptionsVO.setValue(e.getId());
            list.add(elSelectOptionsVO);
        });
        return list;
    }

}
